using Microsoft.AspNetCore.Mvc;
using MESData.ErrorCode;
using MESData.ProductionPlan.API.DTO;
using MESData.ProductionPlan.API.Services;

namespace MESData.ProductionPlan.API.Controllers
{
    /// <summary>
    /// 物品控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller]")]
    public class ItemController : ControllerBase
    {
        private readonly IItemService _itemService;

        public ItemController(IItemService itemService)
        {
            _itemService = itemService;
        }

        /// <summary>
        /// 根据物品ID查询对应的仓库名称和库存
        /// </summary>
        [HttpGet("inventory/{itemId}")]
        public async Task<ApiResult<List<ItemInventoryDto>>> GetItemInventories(int itemId)
        {
            return await _itemService.GetItemInventoriesAsync(itemId);
        }

        /// <summary>
        /// 查询所有物品的分页显示
        /// </summary>
        [HttpPost("query")]
        public async Task<ApiPageing<ItemResultDto>> GetItems([FromBody] ItemQueryDto queryDto)
        {
            return await _itemService.GetItemsAsync(queryDto);
        }
    }
} 